<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-wms__task}">
      <el-form ref="dataForm" :model="dataForm" :rules="dataRule"
        label-width="80px">
        <el-row :gutter="20">
          <el-col :md="9" :sm="9">
            <el-form-item label="托盘条码" prop="contNo">
              <el-input @keyup.enter.native="taskAffirm" ref="inputContNo" v-model="dataForm.contNo" placeholder="请输入托盘条码" maxlength="32"
                clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :md="3" :sm="3">
            <el-form-item>
              <el-button v-if="$hasPermission('wms:task:affirm')" type="primary" @click="taskAffirm()">{{
                $t("affirm")
              }}
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" highlight-current-row border style="width: 100%">
        <el-table-column prop="taskId" label="id" header-align="center" align="center" sortable></el-table-column>
        <el-table-column prop="taskSt" label="任务状态" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.taskSt === 0">初始</el-tag>
            <el-tag v-else-if="scope.row.taskSt === 1" type="warning">执行中</el-tag>
            <el-tag v-else-if="scope.row.taskSt === 2" type="success">已完成</el-tag>
            <el-tag v-else-if="scope.row.taskSt === 3" type="success">出库确认</el-tag>
            <el-tag v-else type="danger">异常</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="taskType" label="任务类型" header-align="center" align="center" min-width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.taskType === '02'" type="info">出库下架</el-tag>
            <el-tag v-else>未知</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="originContNo" label="托盘条码" header-align="center" align="center"
          min-width="220"></el-table-column>
        <el-table-column prop="spuNo" label="砂芯图号" header-align="center" align="center" min-width="150">
        </el-table-column>
        <el-table-column prop="lotNo" label="批次" header-align="center" align="center">
        </el-table-column>
        <el-table-column prop="planQnty" label="计划量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="actlQnty" label="实际量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="originPosition" label="起始位置" header-align="center" align="center" min-width="150">
        </el-table-column>
        <el-table-column prop="targetPosition" label="目标位置" header-align="center" align="center" min-width="150">
        </el-table-column>
        <el-table-column prop="currentPosition" label="当前位置" header-align="center" align="center" min-width="150">
        </el-table-column>
        <el-table-column prop="creatorName" label="创建用户" header-align="center" align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="createDate" label="创建日期" header-align="center" align="center" min-width="155" sortable>
        </el-table-column>
        <el-table-column prop="updaterName" label="更新用户" header-align="center" align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="updateDate" label="更新日期" header-align="center" align="center" min-width="155" sortable>
        </el-table-column>
        <el-table-column prop="comments" label="备注" header-align="center" align="center" show-overflow-tooltip>
        </el-table-column>
      </el-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/wms/task/page",
        getDataListIsPage: true,
      },
      dataForm: {
        taskId: '',
        taskType: '02',
        contNo: '',
        affirmQnty: '1',
      },
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.inputContNo.focus();
    })
  },
  computed: {
    dataRule() {
      return {
        contNo: [
          {
            required: true,
            message: this.$t("validate.required"),
            trigger: "blur",
          },
        ],
      };
    },
  },
  methods: {
    //2.出库确认
    taskAffirm() {
      this.$refs["dataForm"].validate((valid) => {
        if (!valid) {
          return false;
        }
        this.$http
          .post("wms/task/affirm", this.dataForm)
          .then(({ data: res }) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg);
            }
            this.$message({
              message: res.msg,
              type: "success",
              duration: 500,
              onClose: () => {
                this.query();
                this.$nextTick(() => {
                  this.$refs.inputContNo.focus();
                  this.$refs.inputContNo.select();
                })
              },
            });
          })
          .catch(() => { });
      })
    },
  },
};
</script>
